package com.wan37.logic.guild.service.impl;

import com.wan37.logic.guild.dao.GuildWarehouseDao;
import com.wan37.logic.guild.domain.entity.GuildWarehouseDO;
import com.wan37.logic.guild.domain.vo.GuildWarehouseVO;
import com.wan37.logic.guild.service.GuildWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : luoyong
 * @date : 2020-08-04 12:34
 **/
@Service("guildWarehouseService")
public class GuildWarehouseServiceImpl implements GuildWarehouseService {
    @Autowired
    private GuildWarehouseDao guildWarehouseDao;

    @Override
    public boolean update(GuildWarehouseVO guildWarehouseVO) {
        GuildWarehouseDO guildWarehouseDO = new GuildWarehouseDO(guildWarehouseVO);
        return guildWarehouseDao.update(guildWarehouseDO);
    }

    @Override
    public boolean save(GuildWarehouseVO guildWarehouseVO) {
        GuildWarehouseDO guildWarehouseDO = new GuildWarehouseDO(guildWarehouseVO);
        return guildWarehouseDao.add(guildWarehouseDO);
    }

    @Override
    public boolean delete(GuildWarehouseVO guildWarehouseVO) {
        return false;
    }

    @Override
    public List<GuildWarehouseVO> getGuildWarehouseByGuildId(String guildId) {
        List<GuildWarehouseDO> guildWarehouseDOList = guildWarehouseDao.getGuildWarehouseDOByGuildId(guildId);
        List<GuildWarehouseVO> guildWarehouseVOList = null;
        if (guildWarehouseDOList != null) {
            guildWarehouseVOList = new ArrayList<>();
            for (GuildWarehouseDO guildWarehouseDO : guildWarehouseDOList) {
                guildWarehouseVOList.add(new GuildWarehouseVO(guildWarehouseDO));
            }
        }
        return guildWarehouseVOList;
    }

    @Override
    public boolean deleteByGuildIdAndBackpackId(String guildId, String backpackId) {
        return guildWarehouseDao.deleteByGuildIdAndBackpackId(guildId, backpackId);
    }

    @Override
    public boolean deleteByGuildId(String guildId) {
        return guildWarehouseDao.deleteByGuildId(guildId);
    }
}
